package com.sun.controller;

import com.sun.service.LoginService;
import com.sun.pojo.User;
import com.sun.utils.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * @author sun
 * @date 2020/11/4 - 23:06
 */
@Controller
@RequestMapping("login1")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @RequestMapping("toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("toShowScores")
    public String toShowScores(){
        return "showScores";
    }
    /*登录*/
    @RequestMapping("login")
    public String login(User user, Model model){

        User user1 = loginService.login(user);
        if(null!=user1){
            //保存到session
            WebUtils.getHttpSession().setAttribute("user",user1);
            //记录登陆日志 向sys_login_log里面插入数据
            return "showScores";
        }else{
            model.addAttribute("error", "登录失败");
            return "login";
        }

    }

}
